import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline



cv2.getVersionString()


# image 是一个numpy数组 按BGR读取
image=cv2.imread('./img/opencv_logo.jpg')
# cv2.imshow('image',image)
# cv2.waitKey()
plt.imshow(image)


image.shape


# cv2.imshow('image2',image[100:200,::-1,:])
# cv2.waitKey()
# 用matplotlib显示是按照RGB顺序显示的, 所以要对图层翻转操作
plt.imshow(image[:,:,::-1]) 
plt.show()


img2 = cv2.imread('./img/view.jpg')
print(img2.shape)
img2=img2[10:200,10:200]


plt.imshow(img2)


# 将彩色图转为灰度图
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imwrite('./img/view_gray.jpg',gray)





#最多500个特征点,0.1点的质量,特征点之间的距离大于10个像素
corners=cv2.goodFeaturesToTrack(gray,500,0.1,10)  
# corners是 ndarray类型的float32数组


# 在图中标记特征点
for corner in corners:
    x,y=corner.ravel()
    cv2.circle(image,(int(x),int(y)),3,(255,0,255),-1)
# cv2.imshow('corners',image)
# cv2.waitKey()
plt.imshow(image)



